package cn.bluemobi.app.controller.commodity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.bluemobi.app.core.controller.AppBaseController;
import cn.bluemobi.app.entity.output.Comment;
import cn.bluemobi.app.entity.output.Commodity;
import cn.bluemobi.app.entity.output.Specification;
import cn.bluemobi.app.service.CommodityService;
import cn.bluemobi.common.core.dto.Dto;
import cn.bluemobi.common.core.dto.Page;

import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

/**
 * 
 * @author lvxh
 * 
 */
@Controller
@RequestMapping("/commodity")
@Api(description = "商品", value = "commodity")
public class CommodityController extends AppBaseController {

	@Autowired
	private CommodityService commodityService;

	@ApiOperation(value = "商品列表", httpMethod = "POST")
	@RequestMapping("/findCommodityList")
	@ResponseBody
	public Page<Commodity> findCommodityList(
			@RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
			@RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
			@ApiParam("搜索关键字") @RequestParam(value = "keyword", required = false) String keyword,
			@ApiParam("二级分类ID") @RequestParam(value = "secondCategoryId", required = false) String secondCategoryId,
			@ApiParam("是否积分兑换（0否，1是）") @RequestParam(value = "isPointsExchange", required = false) String isPointsExchange,
			@ApiParam("是否3倍积分商品（0否，1是）") @RequestParam(value = "isThreeMultiplePoints", required = false) String isThreeMultiplePoints,
			@ApiParam("是否推荐（0否，1是）") @RequestParam(value = "isRecommend", required = false) String isRecommend,
			@ApiParam("是否新品（0否，1是）") @RequestParam(value = "isNew", required = false) String isNew,
			@ApiParam("价格排序（0从小到大，1从大到小）") @RequestParam(value = "priceSort", required = false) String priceSort,
			@ApiParam("销量排序（0从小到大，1从大到小）") @RequestParam(value = "buyCountSort", required = false) String buyCountSort) {
		return commodityService.findCommodityList(pageNo, pageSize, keyword,
				secondCategoryId, isPointsExchange, isThreeMultiplePoints,
				isRecommend, isNew, priceSort, buyCountSort);
	}

	@ApiOperation(value = "商品详情", httpMethod = "POST")
	@RequestMapping("/findCommodityDetail")
	@ResponseBody
	public Dto<Commodity> findCommodityDetail(
			@ApiParam("会员ID") @RequestParam(value = "memberId", required = false) String memberId,
			@ApiParam("商品ID") @RequestParam("commodityId") String commodityId) {
		return commodityService.findCommodityDetail(memberId, commodityId);
	}

	@ApiOperation(value = "商品规格详情", httpMethod = "POST")
	@RequestMapping("/findSpecificationDetail")
	@ResponseBody
	public Dto<Specification> findSpecificationDetail(
			@ApiParam("商品ID") @RequestParam("commodityId") String commodityId,
			@ApiParam("规格ID") @RequestParam("specificationId") String specificationId) {
		return commodityService.findSpecificationDetail(commodityId,
				specificationId);
	}

	@RequestMapping("/findComments")
	@ApiOperation(value = "查询评价列表", httpMethod = "POST")
	@ResponseBody
	public Page<Comment> findComments(
			@ApiParam("页码") @RequestParam(value = "pageNo", defaultValue = "1") Integer pageNo,
			@ApiParam("每页显示条数") @RequestParam(value = "pageSize", defaultValue = "20") Integer pageSize,
			@ApiParam("商品ID") @RequestParam("commodityId") String commodityId) {
		return commodityService.findComments(pageNo, pageSize, commodityId);
	}
}
